package com.lemon.smartsafety.ui.fragment.safe.contract;

import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.common.SelectDataI;
import com.lemon.smartsafety.entity.event.contract.KeepUnitEvent;
import com.lemon.smartsafety.entity.safe.contract.AgencyInfoVo;
import com.lemon.smartsafety.http.service.KeepContactServices;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.activity.safe.data.contract.KeepContractUnitListActivity;
import com.lemon.smartsafety.ui.adapter.common.SelectAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshNoLoadMoreFragment;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Cooliean on 16/3/31.
 * 维保单位
 */
public class KeepContractUnitListFragment extends BasePullToRefreshNoLoadMoreFragment<SelectDataI, List<AgencyInfoVo>> implements RecyclerTClickListener<SelectDataI> {


    private String mOldValue = null;
    private String mKeyWord  = null;
    private String sTypeId  = null;

    public static KeepContractUnitListFragment newInstance() {
        return new KeepContractUnitListFragment();
    }


    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();
        if (getArguments() != null) {
            mOldValue = StringUtils.nullValue(getArguments().getString(BundleKey.OLD_SELECT_VALUE));
            mKeyWord = StringUtils.nullValue(getArguments().getString(BundleKey.KEY_WORD));
            sTypeId = StringUtils.nullValue(getArguments().getString(BundleKey.TYPE_ID));
        }
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<SelectDataI> getLemonAdapter() {
        return new SelectAdapter(mDataList, this, mOldValue);
    }

    @Override
    public String getHttpTag() {
        return EventTag.TAG_SAFE_KEEP_CONTRACT_LIST;
    }

    @Override
    public void onLoadMore() {

    }

    @Override
    public void onPullRefresh() {
        KeepContactServices.init().getKeepUnitList(mKeyWord, sTypeId);
    }

    @Override
    public void onItemClick(SelectDataI data, int position) {
        KeepUnitEvent event = new KeepUnitEvent();
        event.setTag(KeepContractUnitListFragment.class.getName());
        event.setData(data);
        AppService.getBus().post(event);
        AppManager.getAppManager().finishActivity(KeepContractUnitListActivity.class);

    }
}
